package pt.elvis.revanweb.client.DatabaseObjects;

import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.URL;


public class DatabaseHelper {
	private final static String HEADER = "Content-Type";
	private final static String HEADER_VALUE = "application/x-www-form-urlencoded";
	private final static String phpFilePathPrefix = "phpFiles/"; 
	
	public static void getData_GET(String phpFileName, RequestCallback requestCallback) {
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, phpFilePathPrefix + phpFileName);
		rb.setHeader(HEADER, HEADER_VALUE);
		try {
			rb.sendRequest(null, requestCallback);
		} catch (RequestException e) {
			e.printStackTrace();
		}
	}
	
	public static void getData_POST(String phpFileName, String variavel, RequestCallback requestCallback) {
		RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, phpFilePathPrefix + phpFileName);
		rb.setHeader(HEADER, HEADER_VALUE);
		try {
			rb.sendRequest(URL.encode(variavel), requestCallback);
		} catch (RequestException e) {
			e.printStackTrace();
		}
	}
}
